package com.lyz.dataStructure.algorithm.pinduoduo2019;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 15:58
 * @Description:
 **/

import java.util.Arrays;
import java.util.Scanner;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/7/28 15:58
 *@Description:
 **/
public class Main2 {
    public static void main(String[] args) {

        String[] str ={"CAT","TIGER","RPC"};

        fun(str,0);

    }

    public static void fun(String[] str, int k){
        if(k==str.length){
            System.out.println(Arrays.toString(str));
        }
        for(int i =k;i<str.length;i++){
            if(k>0&&judge(str[k-1],str[i])){
                swap(str,k,i);
                fun(str,k+1);
            }else if(k==0) {
                swap(str,k,i);
                fun(str,k+1);
                swap(str,k,i);
            }
        }
    }

    private  static void swap(String[] a,int s,int i){
        String t = a[s];
        a[s] = a[i];
        a[i] = t ;
    }

    public static boolean judge(String s1,String s2){
        if(s1.charAt(s1.length()-1)==s2.charAt(0)){
            return true;
        }
        return false;
    }
}
